precision highp float;

varying vec2 textureCoordinate;
uniform vec2 pixelStart;
uniform float pixelWidth;
uniform float pixelHeight;
uniform float imageWidthFactor;
uniform float imageHeightFactor;
uniform sampler2D inputTexture;
uniform float pixel;

void main()
{
    if (textureCoordinate.x > pixelStart.x && textureCoordinate.x < (pixelStart.x + pixelWidth) && textureCoordinate.y > pixelStart.y && textureCoordinate.y < (pixelStart.y + pixelHeight)){
        vec2 uv  = textureCoordinate.xy;
        float dx = pixel * imageWidthFactor;
        float dy = pixel * imageHeightFactor;
        vec2 coord = vec2(dx * floor(uv.x / dx), dy * floor(uv.y / dy));
        vec3 tc = texture2D(inputTexture, coord).xyz;
        gl_FragColor = vec4(tc, 1.0);
    } else {
        gl_FragColor = texture2D(inputTexture, textureCoordinate);
    }
}
